Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(papyrus_storage): add append_events function that writes the events of a block to storage #2900

Open
wants to merge 3 commits into
base: alonl/event_storage_split
Choose a base branch
from

Conversation

AlonLStarkWare
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Benchmark movements:
tree_computation_flow performance regressed!
tree_computation_flow time: [34.305 ms 34.803 ms 35.394 ms]
change: [+1.1333% +2.6378% +4.4345%] (p = 0.00 < 0.05)
Performance has regressed.
Found 13 outliers among 100 measurements (13.00%)
3 (3.00%) high mild
10 (10.00%) high severe

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: 3 of 7 files reviewed, 4 unresolved discussions (waiting on @AlonLStarkWare)


crates/papyrus_storage/src/body/events.rs line 377 at r3 (raw file):

    DbCursor<'txn, RO, TransactionIndex, VersionZeroWrapper<TransactionMetadata>, SimpleTable>;

/// interface for updating the events in the storage.

capitalization


crates/papyrus_storage/src/body/events.rs line 382 at r3 (raw file):

    Self: Sized,
{
    /// Appends the events of an entire block to the storage.

Copy this comment:

// To enforce that no commit happen after a failure, we consume and return Self on success.


crates/papyrus_storage/src/body/events.rs line 386 at r3 (raw file):

        self,
        block_number: BlockNumber,
        block_events: Vec<Vec<Event>>,

Receive this by reference and as an array slice and not a vec: &[&[Event]]

In general if you don't need to consume the value it's better to pass it by reference (as long as you don't clone it anywhere)
Also, in general it's better to receive &[T] instead of &Vec as the former can handle the latter yet also handle different stuff like arrays (You'll find that useful in tests for example)


crates/papyrus_storage/src/body/events.rs line 425 at r3 (raw file):

    for (index, transaction_events) in block_events.iter().enumerate() {
        let transaction_index = TransactionIndex(block_number, TransactionOffsetInBlock(index));
        let event_offset = file_handlers.append_events(&transaction_events.clone());

Why clone?

@AlonLStarkWare AlonLStarkWare force-pushed the alonl/append_events branch 2 times, most recently from ab03de4 to 63f915f Compare December 25, 2024 13:14
Copy link
Contributor Author

@AlonLStarkWare AlonLStarkWare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @ShahakShama)


crates/papyrus_storage/src/body/events.rs line 377 at r3 (raw file):

Previously, ShahakShama wrote…

capitalization

Done.


crates/papyrus_storage/src/body/events.rs line 382 at r3 (raw file):

Previously, ShahakShama wrote…

Copy this comment:

// To enforce that no commit happen after a failure, we consume and return Self on success.

Done.


crates/papyrus_storage/src/body/events.rs line 386 at r3 (raw file):

Previously, ShahakShama wrote…

Receive this by reference and as an array slice and not a vec: &[&[Event]]

In general if you don't need to consume the value it's better to pass it by reference (as long as you don't clone it anywhere)
Also, in general it's better to receive &[T] instead of &Vec as the former can handle the latter yet also handle different stuff like arrays (You'll find that useful in tests for example)

Done.


crates/papyrus_storage/src/body/events.rs line 425 at r3 (raw file):

Previously, ShahakShama wrote…

Why clone?

Done

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 5 files at r4, 2 of 5 files at r8, 4 of 4 files at r9, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @AlonLStarkWare and @noamsp-starkware)


crates/papyrus_storage/src/body/mod.rs line 89 at r9 (raw file):

    CommonPrefix,
>;
// TODO: remove the dead code attribute.

Name this TODO on you


crates/papyrus_storage/src/body/events.rs line 415 at r9 (raw file):

                let transaction_index =
                    TransactionIndex(block_number, TransactionOffsetInBlock(index));
                let event_offset = self.file_handlers.append_events(transaction_events);

event -> events
Is this called offset regularly? maybe file_offset for clarity


crates/papyrus_storage/src/body/events.rs line 417 at r9 (raw file):

                let event_offset = self.file_handlers.append_events(transaction_events);
                events_table.append(&self.txn, &transaction_index, &event_offset)?;
                for event in transaction_events {

It looks like in main we gather all the contract addresses of all the events of a single tx and then write them all together. Could you do the same here?


crates/papyrus_storage/src/lib.rs line 725 at r9 (raw file):

    // Appends an event to the corresponding file and returns its location.
    fn append_events(&self, events: &[Event]) -> LocationInFile {
        self.clone().event.append(&events.to_vec())

If you need to do that, then it's better the type will be Vec
So the outer type should be &[&Vec]

@AlonLStarkWare AlonLStarkWare force-pushed the alonl/append_events branch 2 times, most recently from 71dc6a1 to 4c98372 Compare December 31, 2024 09:12
Copy link
Contributor Author

@AlonLStarkWare AlonLStarkWare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 of 7 files reviewed, 4 unresolved discussions (waiting on @noamsp-starkware and @ShahakShama)


crates/papyrus_storage/src/lib.rs line 725 at r9 (raw file):

Previously, ShahakShama wrote…

If you need to do that, then it's better the type will be Vec
So the outer type should be &[&Vec]

Done.


crates/papyrus_storage/src/body/events.rs line 415 at r9 (raw file):

Previously, ShahakShama wrote…

event -> events
Is this called offset regularly? maybe file_offset for clarity

It is only called once. I can change the name to event_location to match the transaction case (where the return value of file_handlers.append_transactions is named tx_location)


crates/papyrus_storage/src/body/mod.rs line 89 at r9 (raw file):

Previously, ShahakShama wrote…

Name this TODO on you

It's already removed in a later PR but sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants